<!DOCTYPE html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <title>Title</title>
  <link rel="stylesheet" href="../../../lib/bootstrap/3.3.5/css/bootstrap.min.css"/>
</head>
<body>
<div id="res">
  <itemlist :mode="mode" :item="curitem" :items="items" :on-edit="onEdit" :on-remove="onRemove" :on-back="backToParent"
            :on-change="onChange" ondown-load="ondownload" :pagenum="pagenum"></itemlist>
</div>
<script src='../../../lib/jquery/2.1.4/jquery-2.1.4.min.js'></script>
<script src='../../../lib/layPage/laypage.js'></script>
<script src='../../../lib/bootstrap/3.3.5/js/bootstrap.min.js'></script>
<script src='../../../node_modules/vue/dist/vue.js'></script>
<script src='../../../lib/vue-resource/0.7.0/vue-resource.js'></script>
<script src="list.js"></script>
<script>
  var AppService = {
    urlroot: 'http://euvee.vicp.co/rest/task/',
    init: function () {
      Vue.http.options.root = this.urlroot;
      Vue.http.headers.common['Token'] = window.localStorage.getItem('Token');
    },
    //初始化引入数据
    find: function (inputQuery, pagenum, pagesteps, items, success_callback, error_callback) {
      var url = this.urlroot;
      Vue.http.get(url, function (data, status, request) {
        var i = data.length;
        success_callback(data, status, request);
      }).catch(function (data, status, request) {
        if (error_callback != null) {
          error_callback(data, status, request);
        }
      });
    }
  }
  var svc = Object.create(AppService);
  // 创建根实例
  var vm = new Vue({
    el: '#res',
    data: {
      items: [],
      pagenum:''
    },
    methods: {
      //高级搜索
      _find: function (inputQuery, pagenum, pagesteps) {
        var self = this;
        svc.find('', pagenum, pagesteps, this.items, function (data, status, request) {
          var a= Object.keys(data)
          //console.log(''+data[a[1]])
          var thisDate = function(curr){
            //返回已经当前页已经分组好的数据
            var last = curr*pagenum - 1;
            last = last >= Object.keys(data).length ? (Object.keys(data).length-1) : last;
            var obj1={}
            var myMap = {};
            for(var i = (curr*pagenum - pagenum); i <= last; i++){
              obj1=data[a[i]];
              myMap[a[i]] = obj1;
            }
            return myMap;
          };
          laypage({
            cont: 'paging', //容器。值支持id名、原生dom对象，jquery对象,
            pages: Math.ceil(Object.keys(data).length/pagenum), //总页数
            skip: true, //是否开启跳页
            skin: '#000000',
            groups: 3, //连续显示分页数
            jump: function(obj){
              self.$set('items', thisDate(obj.curr));
            }});
        });
      }
    },
    ready: function () {
      this._find('', 15, 6);
    }
  })

</script>
</body>
</html>
